function noisy_signal = add_awgn_to_ofdma(signal, snr_dB)
% add_awgn_to_ofdma - 向OFDMA信号添加加性高斯白噪声
%
% 输入参数:
%   signal - 输入信号
%   snr_dB - 信噪比(dB)
%
% 输出参数:
%   noisy_signal - 添加噪声后的信号

% 计算信号功率
signal_power = mean(abs(signal).^2);

% 转换dB为线性比例
snr_linear = 10^(snr_dB/10);

% 计算噪声功率
noise_power = signal_power / snr_linear;

% 生成复高斯白噪声
% 注意OFDMA信号是复数，所以噪声也是复数
noise = sqrt(noise_power/2) * (randn(size(signal)) + 1i*randn(size(signal)));

% 添加噪声到信号
noisy_signal = signal + noise;

% 记录噪声功率和信噪比
measured_noise_power = mean(abs(noise).^2);
measured_snr = 10*log10(signal_power / measured_noise_power);

fprintf('添加AWGN噪声完成:\n');
fprintf('  理论SNR: %.2f dB\n', snr_dB);
fprintf('  实际SNR: %.2f dB\n', measured_snr);

end 